#include "Lexical.h"
#include "Grammatical.h"
#include <fstream>

void readFile(const std::string& path, std::vector<std::string>& context) {
	std::ifstream in(path, std::ios::in);
	while (!in.eof()) {
		std::string str;
		getline(in, str);
		context.push_back(str);
	}
	in.close();
}

void writeFile(const std::string& path, const std::vector<std::pair<std::string, std::string>>& result) {
	std::ofstream out(path, std::ios::out);
	for (auto p : result) {
		if (p.second != "") out << p.first << ' ' << p.second << '\n';
		else out << '<' << p.first << '>' << '\n';
	}
	out.close();
}

int main() {
	const std::string path1 = "testfile.txt";
	const std::string path2 = "output.txt";
	std::vector<std::string> context;
	readFile(path1, context);

	lexical Lexical;
	grammatical Grammatical;
	Lexical.bootLexical();
	Grammatical.bootGrammatical();

	auto words = Lexical.resolve(context);
	auto result = Grammatical.resolve(words);

	writeFile(path2, result);
}